package com.infitecs.eyas.mill.service;

import com.infitecs.eyas.boiler.dao.AirGasParameterDao;
import com.infitecs.eyas.boiler.dao.EfficiencyDao;
import com.infitecs.eyas.boiler.model.AirGasParameter;
import com.infitecs.eyas.boiler.model.Efficiency;
import com.infitecs.eyas.boiler.service.EfficiencyService;
import com.infitecs.eyas.constant.Constant;
import com.infitecs.eyas.expression.model.Formula;
import com.infitecs.eyas.expression.service.ExpressionService;
import com.infitecs.eyas.mill.dao.MillSelectDao;
import com.infitecs.eyas.mill.model.Mill;
import com.infitecs.eyas.mill.model.MillSelect;
import com.infitecs.eyas.nature.dao.NatureDao;
import com.infitecs.eyas.nature.model.Nature;
import com.infitecs.eyas.power.dao.OperateFieldDao;
import com.infitecs.eyas.power.model.OperateField;
import com.infitecs.eyas.quality.dao.AshDao;
import com.infitecs.eyas.quality.dao.BurstDao;
import com.infitecs.eyas.quality.dao.ElementDao;
import com.infitecs.eyas.quality.dao.IndustryDao;
import com.infitecs.eyas.quality.model.Ash;
import com.infitecs.eyas.quality.model.Burst;
import com.infitecs.eyas.quality.model.Element;
import com.infitecs.eyas.quality.model.Industry;
import com.infitecs.eyas.session.SessionService;
import com.infitecs.eyas.session.model.Param;
import com.infitecs.eyas.step.modal.StepInfo;
import com.infitecs.eyas.util.DoubleUtil;
import com.infitecs.krill.ajax.response.AjaxResponse;
import com.infitecs.krill.exception.ValidateErrorException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2015/6/28 0028.
 */
@Service
public class MillSelectService {

    @Autowired
    private MillSelectDao millSelectDao;
    @Autowired
    private SessionService sessionService;
    @Autowired
    private EfficiencyDao efficiencyDao;
    @Autowired
    private ExpressionService expressionService;
    @Autowired
    private ElementDao elementDao;
    @Autowired
    private NatureDao natureDao;
    @Autowired
    private IndustryDao industryDao;
    @Autowired
    private AshDao ashDao;
    @Autowired
    private OperateFieldDao operateFieldDao;
    @Autowired
    private AirGasParameterDao airGasParameterDao;
    @Autowired
    private MillService millService;
    @Autowired
    private BurstDao burstDao;
    @Autowired
    private EfficiencyService efficiencyService;

    public MillSelect getMillSelect() {
        return millSelectDao.getMillSelect(sessionService.getCaseId());
    }

    public void addMillSelect() {
        int caseId = sessionService.getCaseId();
        millSelectDao.addMillSelect(caseId);
        sessionService.addStepState(new StepInfo(caseId, Constant.STEP_ID_11, Constant.STEP_OVER_STATE_0));
    }

    public void saveValueOfMillSelect(Param param) {
        param.setCaseId(sessionService.getCaseId());
        millSelectDao.saveValueOfMillSelect(param);
        param.setParamName(sessionService.getE() + param.getParamName());
        sessionService.putParamMap(param);
    }

    public void chooseSave(MillSelect millSelect) {
        chooseDataSaveValidate(millSelect);
        MillSelect oldSelect = millSelectDao.getMillSelect(millSelect.getCaseId());
        if (oldSelect == null) {
            millSelect.setModelState("0");
        } else {
            OperateField operateField = operateFieldDao.getOperateField(millSelect.getCaseId());
            if(!millSelect.getE7().equals(oldSelect.getE7())){
                millSelect.setModelState("0");
            }else {
                millSelect.setModelState(operateField.getModelState());
            }
            millSelect.setModel(oldSelect.getModel());
        }
        chooseDataSave(millSelect);
    }

    private void chooseDataSaveValidate(MillSelect millSelect) {
        if (millSelect.getMyglState().equals("0")) {
            Efficiency oldEfficiency = efficiencyDao.getEfficiencyByPowerCaseId(millSelect.getCaseId());
            if (oldEfficiency == null) {
                throw new ValidateErrorException("锅炉数据未填写或未全部填写，不能引用锅炉数据！");
            }
        }
    }


    public void chooseDataSave(MillSelect millSelect) {
        AirGasParameter airGasParameter = airGasParameterDao.getAirGasParameter(millSelect.getCaseId());
        Efficiency efficiency = efficiencyDao.getEfficiencyByPowerCaseId(millSelect.getCaseId());
        //获取锅炉参数
        if (millSelect.getMyglState().equals("0")) {
            //E3
            millSelect.setE3(airGasParameter.getHearthAirLeakageRate());
            //E4
            millSelect.setE4(airGasParameter.getHearthOverOutAirCoefficient());
            //E5
            millSelect.setE5(efficiency.getE52());
            //E6
            millSelect.setE6(efficiency.getE93());
            //54
            millSelect.setE54(airGasParameter.getOnceWindRate());
            //67
            millSelect.setE67(airGasParameter.getInOnceWindTemperature());
            //87
            millSelect.setE87(airGasParameter.getOutOnceWindTemperature());
        }
        setChooseSaveData(millSelect);
        MillSelect oldSelect = millSelectDao.getMillSelect(millSelect.getCaseId());
        if (oldSelect == null) {
            millSelect.setModelState("0");
            millSelectDao.addMillSelectData(millSelect);
        } else {
            millSelectDao.updateMillSelect(millSelect);
        }
        OperateField operateField = new OperateField();
        operateField.setMyglState(millSelect.getMyglState());
        operateField.setE12State(millSelect.getE12State());
        operateField.setE74State(millSelect.getE74State());
        operateField.setE75State(millSelect.getE75State());
        operateField.setModelState(millSelect.getModelState());
        operateField.setCaseId(millSelect.getCaseId());
        operateFieldDao.updateOperateFieldMillSelect(operateField);
    }

    private void setChooseSaveData(MillSelect millSelect) {
        Element element = elementDao.getElementByPowerCaseId(millSelect.getCaseId());
        Burst burst = burstDao.getBurstByPowerCaseId(millSelect.getCaseId());
        Industry industry = industryDao.getIndustryByPowerCaseId(millSelect.getCaseId());
        Map<String, Formula> formulaMap = expressionService.getFormulaMapByType(7);
        Map<String, Double> paramMap = new HashMap<>();
        paramMap.put("ME6", industry.getAar());
        paramMap.put("ME30", element.getSar());
        paramMap.put("ME17", element.getQgrAr());
        paramMap.put("ME3", industry.getMar());
        paramMap.put("ME13", element.getQnetAr());
        paramMap.put("ME10", industry.getVdaf());
        paramMap.put("ME21", burst.getHgi());
        paramMap.put("ME10", industry.getVdaf());
        Double E73;
        Double ME10 = paramMap.get("ME10");
        if (ME10 < 40)
            E73 = expressionService.getCalculateData(formulaMap.get("AE73_1"), paramMap);
        else
            E73 = 70.0;
        if (millSelect.getE74State().equals("0")) {
            millSelect.setE74(E73);
            paramMap.put("E74", E73);
        } else {
            paramMap.put("E74", millSelect.getE74());
        }
        millSelect.setE74(paramMap.get("E74"));
        if (millSelect.getE75State().equals("0")) {
            double E75 = expressionService.getCalculateData(formulaMap.get("AE75"), paramMap);
            millSelect.setE75(E75);
        }

        paramMap.put("E2", millSelect.getE2());
        paramMap.put("E3", millSelect.getE3());
        paramMap.put("E4", millSelect.getE4());
        paramMap.put("E5", millSelect.getE5());
        paramMap.put("E6", millSelect.getE6());
        paramMap.put("E7", millSelect.getE7());
        paramMap.put("E8", millSelect.getE8());
        paramMap.put("E9", millSelect.getE9());
        paramMap.put("E54", millSelect.getE54());
        paramMap.put("E67", millSelect.getE67());
        paramMap.put("E87", millSelect.getE87());
        double E10 = expressionService.getCalculateData(formulaMap.get("AE10"), paramMap);
        paramMap.put("E10", E10);
        double E11 = expressionService.getCalculateData(formulaMap.get("AE11"), paramMap);
        paramMap.put("E11", E11);
        //E12
        if (millSelect.getE12State().equals("1")) {
            paramMap.put("E12", millSelect.getE12());
        } else {
            Double E2 = paramMap.get("E2");
            Double ME6 = paramMap.get("ME6");
            Double ME3 = paramMap.get("ME3");
            Double ME13 = paramMap.get("ME13");
            boolean AE12_1 = (ME6 * 100 / (100 - ME3)) > 29 && ME13 > 15510 && ME13 < 17000;
            Double E12;
            if(AE12_1){
                 E12 = 5 + 0.35 * E2 * ME10;
            }else{
                 E12 = (ME10 > 38 && ME3 > 20) ? 35 : 0.5 * E2 * ME10;
            }
            paramMap.put("E12", E12);
            millSelect.setE12(E12);
        }

        //E13
        double E13 = expressionService.getCalculateData(formulaMap.get("AE13"), paramMap);
        paramMap.put("E13", E13);
        //E14
        double E14 = expressionService.getCalculateData(formulaMap.get("AE14"), paramMap);
        paramMap.put("E14", E14);
        //E15
        double E15 = expressionService.getCalculateData(formulaMap.get("AE15"), paramMap);
        paramMap.put("E15", E15);
        //E16
        double E16 = expressionService.getCalculateData(formulaMap.get("AE16"), paramMap);
        paramMap.put("E16", E16);
        //E17
        double E17 = expressionService.getCalculateData(formulaMap.get("AE17"), paramMap);
        paramMap.put("E17", E17);
        //E18
        double E18 = expressionService.getCalculateData(formulaMap.get("AE18"), paramMap);
        paramMap.put("E18", E18);
        //E19
        double E19 = expressionService.getCalculateData(formulaMap.get("AE19"), paramMap);
        paramMap.put("E19", E19);
        //E20
        double E20 = expressionService.getCalculateData(formulaMap.get("AE20"), paramMap);
        paramMap.put("E20", E20);
        //21
        Double ME3 = paramMap.get("ME3");
        double E21 = ME3 <= 10 ? 1 : (1 + (10 - ME3) * 0.0114);
        paramMap.put("E21", E21);
        //E22
        double E22 = expressionService.getCalculateData(formulaMap.get("AE22"), paramMap);
        paramMap.put("E22", E22);
        //E23
        if (E11 <= 32.6) {
            if (ME3 <= 12)
                paramMap.put("E23", 1.0);
            else
                paramMap.put("E23", DoubleUtil.getInstance().get4Double(1 + (12 - ME3) * 0.0125));
        } else {
            if (ME3 <= 8)
                paramMap.put("E23", 1.0);
            else
                paramMap.put("E23", DoubleUtil.getInstance().get4Double(1 + (8 - ME3) * 0.0125));
        }
        //E24
        if (ME3 < 10)
            paramMap.put("E24", 0.0);
        else if (ME3 >= 10 && ME3 <= 14)
            paramMap.put("E24", DoubleUtil.getInstance().get4Double(1 + 0.0125 * (10 - ME3)));
        else
            paramMap.put("E24", 0.0);
        //E25
        Double ME6 = paramMap.get("ME6");
        if (ME6 > 20)
            paramMap.put("E25", DoubleUtil.getInstance().get4Double(1 + 0.005 * (20 - ME6)));
        else
            paramMap.put("E25", 1.0);
        //E26
        if (ME6 <= 20)
            paramMap.put("E26", 1.2);
        else if (ME6 >= 40)
            paramMap.put("E26", 1.05);
        else
            paramMap.put("E26", DoubleUtil.getInstance().get4Double(1.05 + (40 - ME6) * 0.0075));
        //E28
        double E28 = expressionService.getCalculateData(formulaMap.get("AE28"), paramMap);
        paramMap.put("E28", E28);
        //E32
        Double E32;
        Double E12 = paramMap.get("E12");
        if (E12 > 25) {
            E32 = 1.0;
        } else if (E12 >= 18 && E12 <= 25) {
            E32 = 1 + (25 - E12) * 0.01;
        } else {
            E32 = 1.07;
        }
        paramMap.put("E27", 1.0);
        paramMap.put("E29", 0.95);
        paramMap.put("E30", 0.9);
        paramMap.put("E31", 1.0);
        paramMap.put("E32", E32);
        //E33
        double E33 = 0.0;
        Double E7 = paramMap.get("E7");
        if (E7.equals(1.0) || E7.equals(2.0) || E7.equals(3.0) || E7.equals(4.0) || E7.equals(5.0) || E7.equals(6.0)) {
            E33 = expressionService.getCalculateData(formulaMap.get("AE33_1"), paramMap);
        } else if (E7.equals(7.0)) {
            E33 = expressionService.getCalculateData(formulaMap.get("AE33_2"), paramMap);
        } else if (E7.equals(8.0)) {
            E33 = expressionService.getCalculateData(formulaMap.get("AE33_3"), paramMap);
        } else if (E7.equals(9.0)) {
            E33 = expressionService.getCalculateData(formulaMap.get("AE33_4"), paramMap);
        }
        MillSelect oldSelect = millSelectDao.getMillSelect(millSelect.getCaseId());
        if (oldSelect == null || "0".equals(millSelect.getModelState())) {
            millSelect.setModelState("0");
            Mill mill = millService.getMill(E33, E7.intValue());
            if (mill == null) {
                throw new ValidateErrorException("要求磨煤机最小基本出力超出范围，请调整磨煤机类型或数量！");
            }
            millSelect.setModel(mill.getModel());
        }
    }

    public Map<String, Double> getChooseDataByCaseId(int caseId) {
        MillSelect millSelect = millSelectDao.getMillSelect(caseId);
        OperateField operateField = operateFieldDao.getOperateField(caseId);
        millSelect.setMyglState(operateField.getMyglState());
        millSelect.setE12State(operateField.getE12State());
        millSelect.setE74State(operateField.getE74State());
        millSelect.setE75State(operateField.getE75State());
        millSelect.setModelState(operateField.getModelState());
        return getChooseData(millSelect);
    }

    private Map<String, Double> getChooseData(MillSelect millSelect) {
        Element element = elementDao.getElementByPowerCaseId(millSelect.getCaseId());
        Burst burst = burstDao.getBurstByPowerCaseId(millSelect.getCaseId());
        Industry industry = industryDao.getIndustryByPowerCaseId(millSelect.getCaseId());
        Nature nature = natureDao.getNatureByPowerCaseId(millSelect.getCaseId());
        Map<String, Formula> formulaMap = expressionService.getFormulaMapByType(7);
        Map<String, Double> paramMap = new HashMap<>();
        paramMap.put("ME6", industry.getAar());
        paramMap.put("ME30", element.getSar());
        paramMap.put("ME17", element.getQgrAr());
        paramMap.put("ME3", industry.getMar());
        paramMap.put("ME13", element.getQnetAr());
        paramMap.put("ME10", industry.getVdaf());
        paramMap.put("ME21", burst.getHgi());
        paramMap.put("ME10", industry.getVdaf());
        paramMap.put("ME26", element.getCar());
        paramMap.put("ME27", element.getHar());
        paramMap.put("ME28", element.getOar());
        paramMap.put("ME29", element.getNar());
        paramMap.put("ME30", element.getSar());
        paramMap.put("ZE4", nature.getLocalPressure());
        paramMap.put("ZE6", 101.325);
        paramMap.put("ZE14", nature.getAnnualAverageAirMoisture());
        paramMap.put("ZE15", nature.getLocalDensityMoistAir());
        paramMap.put("ZE12", nature.getMinDailyAverageTemperature());


        Double E73;
        Double ME10 = paramMap.get("ME10");
        if (ME10 < 40)
            E73 = expressionService.getCalculateData(formulaMap.get("AE73_1"), paramMap);
        else
            E73 = 70.0;
        if (millSelect.getE74State().equals("0")) {
            millSelect.setE74(E73);
            paramMap.put("E74", E73);
        } else {
            paramMap.put("E74", millSelect.getE74());
        }
        paramMap.put("E73", E73);

        if (millSelect.getE75State().equals("0")) {
            double E75 = expressionService.getCalculateData(formulaMap.get("AE75"), paramMap);
            paramMap.put("E75", E75);
        } else {
            paramMap.put("E75", millSelect.getE75());
        }

        paramMap.put("E2", millSelect.getE2());
        paramMap.put("E3", millSelect.getE3());
        paramMap.put("E4", millSelect.getE4());
        paramMap.put("E5", millSelect.getE5());
        paramMap.put("E6", millSelect.getE6());
        paramMap.put("E7", millSelect.getE7());
        paramMap.put("E8", millSelect.getE8());
        paramMap.put("E9", millSelect.getE9());
        paramMap.put("E54", millSelect.getE54());
        paramMap.put("E67", millSelect.getE67());
        paramMap.put("E87", millSelect.getE87());
        double E10 = expressionService.getCalculateData(formulaMap.get("AE10"), paramMap);
        paramMap.put("E10", E10);
        double E11 = expressionService.getCalculateData(formulaMap.get("AE11"), paramMap);
        paramMap.put("E11", E11);
        //E12
        if (millSelect.getE12State().equals("1")) {
            paramMap.put("E12", millSelect.getE12());
        } else {
            Double E2 = paramMap.get("E2");
            Double ME6 = paramMap.get("ME6");
            Double ME3 = paramMap.get("ME3");
            Double ME13 = paramMap.get("ME13");
            boolean AE12_1 = (ME6 * 100 / (100 - ME3)) > 29 && ME13 > 15510 && ME13 < 17000;
            Double AE12_2 = 5 + 0.35 * E2 * ME10;
            Double AE12_3 = (ME10 > 38 && ME3 > 20) ? 35 : 0.5 * E2 * ME10;
            double E12 = AE12_1 ? AE12_2 : AE12_3;
            paramMap.put("E12", E12);
        }

        //E13
        double E13 = expressionService.getCalculateData(formulaMap.get("AE13"), paramMap);
        paramMap.put("E13", E13);
        //E14
        double E14 = expressionService.getCalculateData(formulaMap.get("AE14"), paramMap);
        paramMap.put("E14", E14);
        //E15
        double E15 = expressionService.getCalculateData(formulaMap.get("AE15"), paramMap);
        paramMap.put("E15", E15);
        //E16
        double E16 = expressionService.getCalculateData(formulaMap.get("AE16"), paramMap);
        paramMap.put("E16", E16);
        //E17
        double E17 = expressionService.getCalculateData(formulaMap.get("AE17"), paramMap);
        paramMap.put("E17", E17);
        //E18
        double E18 = expressionService.getCalculateData(formulaMap.get("AE18"), paramMap);
        paramMap.put("E18", E18);
        //E19
        double E19 = expressionService.getCalculateData(formulaMap.get("AE19"), paramMap);
        paramMap.put("E19", E19);
        //E20
        double E20 = expressionService.getCalculateData(formulaMap.get("AE20"), paramMap);
        paramMap.put("E20", E20);
        //21
        Double ME3 = paramMap.get("ME3");
        double E21 = ME3 <= 10 ? 1 : (1 + (10 - ME3) * 0.0114);
        paramMap.put("E21", E21);
        //E22
        double E22 = expressionService.getCalculateData(formulaMap.get("AE22"), paramMap);
        paramMap.put("E22", E22);
        //E23
        if (E11 <= 32.6) {
            if (ME3 <= 12)
                paramMap.put("E23", 1.0);
            else
                paramMap.put("E23", DoubleUtil.getInstance().get4Double(1 + (12 - ME3) * 0.0125));
        } else {
            if (ME3 <= 8)
                paramMap.put("E23", 1.0);
            else
                paramMap.put("E23", DoubleUtil.getInstance().get4Double(1 + (8 - ME3) * 0.0125));
        }
        //E24
        if (ME3 < 10)
            paramMap.put("E24", 0.0);
        else if (ME3 >= 10 && ME3 <= 14)
            paramMap.put("E24", DoubleUtil.getInstance().get4Double(1 + 0.0125 * (10 - ME3)));
        else
            paramMap.put("E24", 0.0);
        //E25
        Double ME6 = paramMap.get("ME6");
        if (ME6 > 20)
            paramMap.put("E25", DoubleUtil.getInstance().get4Double(1 + 0.005 * (20 - ME6)));
        else
            paramMap.put("E25", 1.0);
        //E26
        if (ME6 <= 20)
            paramMap.put("E26", 1.2);
        else if (ME6 >= 40)
            paramMap.put("E26", 1.05);
        else
            paramMap.put("E26", DoubleUtil.getInstance().get4Double(1.05 + (40 - ME6) * 0.0075));
        //E28
        double E28 = expressionService.getCalculateData(formulaMap.get("AE28"), paramMap);
        paramMap.put("E28", E28);
        //E32
        Double E32;
        Double E12 = paramMap.get("E12");
        if (E12 > 25) {
            E32 = 1.0;
        } else if (E12 >= 18 && E12 <= 25) {
            E32 = 1 + (25 - E12) * 0.01;
        } else {
            E32 = 1.07;
        }
        paramMap.put("E27", 1.0);
        paramMap.put("E29", 0.95);
        paramMap.put("E30", 0.9);
        paramMap.put("E31", 1.0);
        paramMap.put("E32", E32);
        //E33
        double E33 = 0.0;
        Double E7 = paramMap.get("E7");
        if (E7.equals(1.0) || E7.equals(2.0) || E7.equals(3.0) || E7.equals(4.0) || E7.equals(5.0) || E7.equals(6.0)) {
            E33 = expressionService.getCalculateData(formulaMap.get("AE33_1"), paramMap);
        } else if (E7.equals(7.0)) {
            E33 = expressionService.getCalculateData(formulaMap.get("AE33_2"), paramMap);
        } else if (E7.equals(8.0)) {
            E33 = expressionService.getCalculateData(formulaMap.get("AE33_3"), paramMap);
        } else if (E7.equals(9.0)) {
            E33 = expressionService.getCalculateData(formulaMap.get("AE33_4"), paramMap);
        }
        Mill mill = millService.getMill(millSelect.getModel(), E7.intValue());
        paramMap.put("E33", E33);
        paramMap.put("E34", mill.getBaseOutput());
        paramMap.put("E39", mill.getDrag());
        if (E7 == 8) {
            if (millSelect.getSplitterType().equals("1")) {
                paramMap.put("E43", mill.getCapacitySt());
            } else {
                paramMap.put("E43", mill.getCapacityDy());
            }
        } else {
            paramMap.put("E43", mill.getCapacity());
        }
        if (E7 == 7) {
            if (ME10 > 37 && ME3 > 20) {
                paramMap.put("E52", mill.getVentilationH());
            } else {
                paramMap.put("E52", mill.getVentilationY());
            }
        } else if (E7 == 9) {
            //todo 需要公式计算
        } else {
            paramMap.put("E52", mill.getVentilation());
        }
        if (E7 == 7 || E7 == 8 || E7 == 9) {
            //todo 需要后续计算
        } else {
            paramMap.put("107", mill.getSeal());
        }
        //E35
        double E35 = expressionService.getCalculateData(formulaMap.get("AE35"), paramMap);
        paramMap.put("E35", E35);

        Double E36;
        if (E7.equals(1.0) || E7.equals(2.0) || E7.equals(3.0) || E7.equals(4.0) || E7.equals(5.0) || E7.equals(6.0) || E7.equals(7.0)) {
            E36 = expressionService.getCalculateData(formulaMap.get("AE36_1"), paramMap);
        } else if (E7.equals(8.0)) {
            E36 = expressionService.getCalculateData(formulaMap.get("AE36_2"), paramMap);
        } else {
            E36 = expressionService.getCalculateData(formulaMap.get("AE36_3"), paramMap);
        }
        paramMap.put("E36", E36);

        paramMap.put("E37",  DoubleUtil.getInstance().get4Double(E35 / E10));

        //E38
        double E38 = expressionService.getCalculateData(formulaMap.get("AE38"), paramMap);
        paramMap.put("E38", E38);
        //E40
        double E40 = expressionService.getCalculateData(formulaMap.get("AE40"), paramMap);
        paramMap.put("E40", E40);
        //E41
        double E41 = expressionService.getCalculateData(formulaMap.get("AE41"), paramMap);
        paramMap.put("E41", E41);
        //E42
        double E42;
        if (E7.equals(1.0) || E7.equals(2.0) || E7.equals(3.0) || E7.equals(4.0) || E7.equals(5.0) || E7.equals(6.0) || E7.equals(7.0)) {
            E42 = expressionService.getCalculateData(formulaMap.get("AE42_1"), paramMap);
        } else {
            E42 = expressionService.getCalculateData(formulaMap.get("AE42_2"), paramMap);
        }
        paramMap.put("E42", E42);
        //E44
        double E44 = expressionService.getCalculateData(formulaMap.get("AE44"), paramMap);
        paramMap.put("E44", E44);
        //E45
        double E45 = expressionService.getCalculateData(formulaMap.get("AE45"), paramMap);
        paramMap.put("E45", E45);
        //E46
        double E46 = expressionService.getCalculateData(formulaMap.get("AE46"), paramMap);
        paramMap.put("E46", E46);
        //E47
        double E47 = expressionService.getCalculateData(formulaMap.get("AE47"), paramMap);
        paramMap.put("E47", E47);
        //E50
        Double E50;
        if (E38 > 25)
            E50 = DoubleUtil.getInstance().get4Double(66.666667 + 0.3333333 * E38);
        else
            E50 = 75.0;
        paramMap.put("E50", E50);

        Double E51;
        if (E38 > 25)
            E51 = DoubleUtil.getInstance().get4Double(60 + 0.4 * E38);
        else
            E51 = 70.0;
        paramMap.put("E51", E51);
        //E56
        double E56 = expressionService.getCalculateData(formulaMap.get("AE56"), paramMap);
        paramMap.put("E56", E56);
        //E58
        Double E58;
        if (E7.equals(1.0) || E7.equals(2.0) || E7.equals(3.0) || E7.equals(4.0) || E7.equals(5.0) || E7.equals(6.0) || E7.equals(7.0)) {
            E58 = expressionService.getCalculateData(formulaMap.get("AE58_1"), paramMap);
        } else {
            E58 = expressionService.getCalculateData(formulaMap.get("AE58_2"), paramMap);
        }
        paramMap.put("E58", E58);
        //E52
        if (E7 == 9) {
            paramMap.put("E52", E58);
        }
        //E53
        Double E53;
        Double E52 = paramMap.get("E52");
        if (E7.equals(1.0) || E7.equals(2.0) || E7.equals(3.0) || E7.equals(4.0) || E7.equals(5.0) || E7.equals(6.0) || E7.equals(7.0)) {
            E53 = E52 * 0.75;
        } else {
            E53 = E52 * 0.7;
        }
        paramMap.put("E53", E53);
        //E55
        Double E55;
        if (E7.equals(1.0) || E7.equals(2.0) || E7.equals(3.0) || E7.equals(4.0) || E7.equals(5.0) || E7.equals(6.0) || E7.equals(7.0)) {
            E55 = expressionService.getCalculateData(formulaMap.get("AE55_1"), paramMap);
        } else {
            E55 = expressionService.getCalculateData(formulaMap.get("AE55_2"), paramMap);
        }
        paramMap.put("E55", E55);
        //E57
        double E57 = expressionService.getCalculateData(formulaMap.get("AE57"), paramMap);
        paramMap.put("E57", E57);
        paramMap.put("E61", millSelect.getE61());
        //E59
        if (E52 >= E58 && E56 >= E53)
            paramMap.put("E59", 1.0);
        else
            paramMap.put("E59", 0.0);
        //E63
        double E63;
        Double ME13 = paramMap.get("ME13");
        if (ME3 == null || ME13 == null)
            E63 = 0.0;
        else
            E63 = 20;
        paramMap.put("E63", E63);
        //E64
        double E64 = expressionService.getCalculateData(formulaMap.get("AE64"), paramMap);
        paramMap.put("E64", E64);
        //E65
        double E65;
        if (ME3 < (ME13 * 0.001) / 0.65)
            E65 = 0.0;
        else
            E65 = 20 * E64;
        paramMap.put("E65", DoubleUtil.getInstance().get4Double(E65));
        //E66
        Double E66;
        if (E7.equals(1.0) || E7.equals(2.0) || E7.equals(3.0) || E7.equals(4.0) || E7.equals(5.0) || E7.equals(6.0) || E7.equals(7.0)) {
            E66 = 0.6 * 20;
        } else {
            E66 = 0.6 * 22;
        }
        paramMap.put("E66", E66);
        //E68
        double E68 = expressionService.getCalculateData(formulaMap.get("AE68"), paramMap);
        paramMap.put("E68", E68);
        //E69
        Double E69;
        Double E61 = paramMap.get("E61");
        if (E61 == 0)
            E69 = E56 * 0.05;
        else
            E69 = 0.0;
        paramMap.put("E69", E69);

        //E70
        double E70 = expressionService.getCalculateData(formulaMap.get("AE70"), paramMap);
        paramMap.put("E70", E70);
        //E71
        double E71 = expressionService.getCalculateData(formulaMap.get("AE71"), paramMap);
        paramMap.put("E71", E71);
        //E76
        double E76 = expressionService.getCalculateData(formulaMap.get("AE76"), paramMap);
        paramMap.put("E76", E76);
        //E77
        double E77 = expressionService.getCalculateData(formulaMap.get("AE77"), paramMap);
        paramMap.put("E77", E77);
        //E79
        double E79 = expressionService.getCalculateData(formulaMap.get("AE79"), paramMap);
        paramMap.put("E79", E79);
        //E80
        double E80;
        if (ME10 > 10) {
            E80 = expressionService.getCalculateData(formulaMap.get("AE80_1"), paramMap);
        } else {
            E80 = expressionService.getCalculateData(formulaMap.get("AE80_2"), paramMap);
        }
        paramMap.put("E80", E80);
        double E81;

        if (paramMap.get("ZE12") > 0)
            E81 = 0.0;
        else
            E81 = expressionService.getCalculateData(formulaMap.get("AE81_1"), paramMap);
        paramMap.put("E81", E81);
        //E82
        double E82 = expressionService.getCalculateData(formulaMap.get("AE82"), paramMap);
        paramMap.put("E82", E82);
        //E84
        Double E84;
        if (E61 == 0)
            E84 = expressionService.getCalculateData(formulaMap.get("AE84_1"), paramMap);
        else
            E84 = expressionService.getCalculateData(formulaMap.get("AE84_2"), paramMap);
        paramMap.put("E84", E84);
        //E86
        double E86 = expressionService.getCalculateData(formulaMap.get("AE86"), paramMap);
        paramMap.put("E86", E86);
        //E88
        double E88 = expressionService.getCalculateData(formulaMap.get("AE88"), paramMap);
        paramMap.put("E88", E88);
        //E89
        double E89 = expressionService.getCalculateData(formulaMap.get("AE89"), paramMap);
        paramMap.put("E89", E89);
        //E90
        double E90 = expressionService.getCalculateData(formulaMap.get("AE90"), paramMap);
        paramMap.put("E90", E90);
        //E91
        double E91 = expressionService.getCalculateData(formulaMap.get("AE91"), paramMap);
        paramMap.put("E91", E91);
        //E92
        double E92 = expressionService.getCalculateData(formulaMap.get("AE92"), paramMap);
        paramMap.put("E92", E92);
        //E93
        double E93 = expressionService.getCalculateData(formulaMap.get("AE93"), paramMap);
        paramMap.put("E93", E93);
        //E94<0.003
        Double E94 = expressionService.getCalculateData(formulaMap.get("AE94_1"), paramMap);
        paramMap.put("E94", E94);
        //E95<0.003
        Efficiency oldEfficiency = efficiencyDao.getEfficiencyByPowerCaseId(millSelect.getCaseId());
        if(oldEfficiency!=null){
            AjaxResponse ajaxResponse = efficiencyService.getAirGasMedian(millSelect.getCaseId());
            paramMap.put("GE40", (Double) ajaxResponse.getReturnData().get("e82"));
            Double E95 = expressionService.getCalculateData(formulaMap.get("AE95_1"), paramMap);
            paramMap.put("E95", E95);
        }
        //E97
        double E97 = expressionService.getCalculateData(formulaMap.get("AE97"), paramMap);
        paramMap.put("E97", E97);
        //E98
        double E98 = expressionService.getCalculateData(formulaMap.get("AE98"), paramMap);
        paramMap.put("E98", E98);
        //E99
        double E99 = expressionService.getCalculateData(formulaMap.get("AE99"), paramMap);
        paramMap.put("E99", E99);
        //E100
        double E100 = expressionService.getCalculateData(formulaMap.get("AE100"), paramMap);
        paramMap.put("E100", E100);
        //E102
        double E102 = expressionService.getCalculateData(formulaMap.get("AE102"), paramMap);
        paramMap.put("E102", E102);
        //E103
        Double E103;
        if (0 < E102 && E102 <= 9)
            E103 = expressionService.getCalculateData(formulaMap.get("AE103_1"), paramMap);
        else if (9 < E102 && E102 <= 512)
            E103 = expressionService.getCalculateData(formulaMap.get("AE103_2"), paramMap);
        else
            E103 = expressionService.getCalculateData(formulaMap.get("AE103_3"), paramMap);
        paramMap.put("E103", E103);
        //E105
        double E105 = expressionService.getCalculateData(formulaMap.get("AE105"), paramMap);
        paramMap.put("E105", E105);
        //E106
        double E106 = expressionService.getCalculateData(formulaMap.get("AE106"), paramMap);
        paramMap.put("E106", E106);
        //E107
        if (E7 == 7 || E7 == 8 || E7 == 9) {
            double E107 = E69 * 3.6;
            paramMap.put("E107", E107);
        }else {
            paramMap.put("E107", mill.getSeal());
        }
        //E108
        double E108 = expressionService.getCalculateData(formulaMap.get("AE108"), paramMap);
        paramMap.put("E108", E108);
        //E109
        double E109 = expressionService.getCalculateData(formulaMap.get("AE109"), paramMap);
        paramMap.put("E109", E109);
        //E110
        double E110= expressionService.getCalculateData(formulaMap.get("AE110"), paramMap);
        paramMap.put("E110", E110);
        //E111
        double E111 = 0;
        if (E106 * 3.6 / E99 > E10)
            E111 =  E106 * 3.6 / E99;
        paramMap.put("E111",  DoubleUtil.getInstance().get4Double(E111));
        return paramMap;
    }
}
